package com.cmpe451.nutty.mobileapi;

import com.cmpe451.nutty.model.ApiUser;

public class ApiThreadLocal {
	public static final ThreadLocal<ApiThreadLocal> threadLocal = new ThreadLocal<ApiThreadLocal>();

	private ApiUser apiUser = null;

	public static void set(ApiUser apiUser) {
		ApiThreadLocal apiThreadLocal = threadLocal.get();

		if (apiThreadLocal == null) {
			apiThreadLocal = new ApiThreadLocal();
		}

		apiThreadLocal.apiUser = apiUser;
		threadLocal.set(apiThreadLocal);
	}

	public static void unset() {
		threadLocal.remove();
	}

	public static ApiUser get() {
		ApiThreadLocal apiThreadLocal = threadLocal.get();

		if (apiThreadLocal == null) {
			return null;
		}

		return apiThreadLocal.apiUser;
	}
}
